package cn.vendsystem.com.config;

import cn.vendcommon.com.interceptor.RequireLoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    private final RedisTemplate redisTemplate;

    public WebMvcConfig(RedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // true 表示全局拦截，false 表示只拦截加了注解的方法
        registry.addInterceptor(new RequireLoginInterceptor(redisTemplate))
                .addPathPatterns("/**") // 要拦截的路径
                .excludePathPatterns(
                        "/system/login/wxMin"
                );
    }
}
